import MySQLdb, tagpot

cursor = tagpot.dbConnect()
cursor.execute("""select anchor,id from word""")
data = cursor.fetchall()
for d in data:
    ids = d[0]
    ds = ids.split(",")
    ds.sort()
    tmp = ''
    rid = ''
    for id in ds:
        if id == tmp:
            #print ids
            print id
            continue
        if rid is '':
            rid = id
        else:
            rid = rid + ","+id
        tmp = id
    if rid[0] is ',':
        rid = rid[1:]
        #print rid[0]
    qu = "update word SET anchor='%s' where id=%s" % (rid, d[1])
    #print qu
    #cursor.execute(qu)
         
        